<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="产线:" prop="lineNo">
          <el-select v-model="formModel.lineNo" clearable filterable>
            <el-option
              v-for="item in lineOptions"
              :key="item.lineNo"
              :label="item.lineNo+'-'+item.lineNameC"
              :value="item.lineNo"
            />
          </el-select>
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button
              v-if="hasPermission('vinPrint_select')"
              type="primary"
              plain
              @click="queryList(false)"
            >查询
            </el-button>
            <el-button
              v-if="hasPermission('vinPrint_select')"
              type="primary"
              plain
              @click="handlePrint(false)"
            >打印
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData" :columns="columns" :is-select="false" :auto-width="false" />
  </div>
</template>

<script>
export default {
  name: 'VinPrintList',
  props: {},
  data() {
    return {
      // 产线列表
      lineOptions: [],
      dialogVisible: false,
      tableData: [],
      printNum: '',
      formModel: {
        lineNo: ''
      },
      columns: [
        { title: 'vin', key: 'vin' },
        { title: '订单号', key: 'orderId' },
        { title: '工厂代码', key: 'plantNo' },
        { title: '工厂名称', key: 'plantNameC' },
        { title: '车型', key: 'productTypeKey', clcd: 'key_product_type' },
        { title: '整车物料号', key: 'materialNo' },
        { title: '车辆状态', key: 'carStatus', clcd: 'car_status_cd' }
      ]
    }
  },
  computed: {},
  mounted() {
    const param = {}
    param.isDelete = '0'
    param.status = '1'
    this.getLineOptions(param)
  },
  methods: {
    queryList() {
      if (this.formModel.lineNo === '') {
        this.$warn('请选择产线!')
        return
      }
      this.$refs.table.query('/vinPrint/pageVinPrint', this.formModel, '', false)
    },
    // 获取产线列
    getLineOptions(param) {
      this.get('/vinPrint/listOnlineLine', param).then(res => {
        this.lineOptions = res
      })
    },
    // 打印
    handlePrint() {
      if (this.tableData.length === 0) {
        this.$warn('请先查询数据!')
        return
      }
      const param = { vin: this.tableData.shift().vin }
      this.post('vinPrint/printVin', param).then(_ => {
        this.$info('打印成功', this.queryList)
      })
    }
  }
}
</script>
